#!/usr/bin/env sh
cd "${0%/*}" || exit

if ! test -e plugins
then
  mkdir -p plugins
fi

if ! test -e plugins.d
then
  mkdir -p plugins.d
fi

case $1 in
  enable)
    for dir in `ls plugins`
    do
      version_dir="plugins.d/$dir"
      if ! test -e $version_dir
      then
        mkdir -p $version_dir
      fi
      target_jar="$version_dir/$2.jar"
      source_jar="plugins/$dir/$2.jar"
      if test -e $source_jar
      then
        ln -s "../../$source_jar" $target_jar
      fi
    done
    ;;
  disable)
    for dir in `ls plugins`
    do
      unlink "plugins.d/$dir/$2.jar"
    done
    ;;
  *)
    echo "Usage: plugin enable [plugin-name]"
    echo "       plugin disable [plugin-name]"
esac